/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package action.activity;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import myUtils.Constants;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.SessionAware;
import po.Activity;
import service.ActivityService;
import myUtils.Constants;
import org.apache.struts2.interceptor.SessionAware;
import po.User;
import po.Useractrelation;
import service.OrgService;
/**
 *
 * @author HX
 */
public class GetActivityAction extends ActionSupport implements ServletRequestAware
{
    private HttpServletRequest request;
    private ActivityService activityService;
    private OrgService orgService;
    private Activity activity;
    private boolean isActor;
    private boolean isAdmin;
    private int userId;
    private List<Useractrelation> useractrelations;
    private boolean isNewActivity;

    @Override
    public String execute()
    {
        int activityId;
        String msg="";
        if (ActionContext.getContext().getSession().get("user") == null) {
            msg = "you should login first";
            request.setAttribute("msg", msg);
            return ERROR;
         }
        userId = ((User) ActionContext.getContext().getSession().get("user")).getId();
        if(request.getParameter("activityId")==null)
         {
             msg="no activity id!!!";
             request.setAttribute("msg", msg);
             return ERROR;
         }
        activityId = Integer.parseInt(request.getParameter("activityId"));
        isActor = activityService.isActor(activityId, userId);
        activity = activityService.getActivity(activityId);
        isNewActivity = (activity.getStarttime().getTime()>new Date().getTime())?true:false;
        useractrelations = activityService.getUseractrelation(activityId);
        isAdmin = orgService.isLeader(userId, activity.getOrganization().getId());
        return SUCCESS;

    }

    public void setActivityService(ActivityService activityService)
    {
        this.activityService=activityService;
    }

    public ActivityService getActivityService()
    {
        return this.activityService;
    }

    public void setServletRequest(HttpServletRequest request)
    {
        this.request=request;
    }
    public HttpServletRequest getServletRequest(){
        return this.request;
    }

    public void setActivity(Activity activity){
        this.activity = activity;
    }

    public Activity getActivity(){
        return this.activity;
    }

    public void setIsActor(boolean isActor){
        this.isActor = isActor;
    }

    public boolean getIsActor(){
        return this.isActor;
    }

    public void setIsAdmin(boolean isAdmin){
        this.isAdmin = isAdmin;
    }

    public boolean getIsAdmin(){
        return this.isAdmin;
    }
    
    public void setOrgService(OrgService orgService)
    {
        this.orgService=orgService;
    }

    public OrgService getOrgService()
    {
        return this.orgService;
    }

    public void setUserId(int userId)
    {
        this.userId=userId;
    }

    public int getUserId()
    {
        return this.userId;
    }

    public void setIsNewActivity(boolean isNewActivity)
    {
        this.isNewActivity=isNewActivity;
    }

    public boolean getIsNewActivity()
    {
        return this.isNewActivity;
    }

    public List<Useractrelation> getUseractrelations() {
        return useractrelations;
    }

    public void setUseractrelations(List<Useractrelation> useractrelations) {
        this.useractrelations = useractrelations;
    }

    /*public void setSession(Map session)
    {
        this.session=session;
    }*/

}

